import HRDCCustomerApi from '@/api/HRDCCustomer.api.js'
import commonApi from '@/api/common.api.js'
import visibvleTreeList from '../HRDC-common/visibleTreeList.vue'

export default {
  data () {
    return {
      dolderNames: '',
      salesIds: [],
      treeData: [],
      productdeliverystatus: []
    }
  },
  components: {
    visibvleTreeList
  },
  computed: {
    tipIsShow () {
      if (this.dolderNames) {
        return true
      } else {
        return false
      }
    }
  },
  created () {
    this.getVisibleTreeList()
  },
  methods: {
    // 跳往详情
    gotoDetail (id) {
      this.$router.push({ name: 'h-c-detail', query: { id: id } })
    },
    // 获取当前角色可见的销售人员
    getVisibleTreeList () {
      HRDCCustomerApi.GetTreeList().then(res => {
        console.log(res)
        this.treeData = res.data.data
      })
    },
    chooseSaler () {
      this.$refs.treeModal.show()
    },
    salersClear () {
      console.log(22222)
      this.salesIds = []
      this.getVisibleTreeList()
    },
    getSalerId (val) {
      console.log(val)
      let idArr = []
      let nameArr = []
      val.forEach(item => {
        if (item.type === "4") {
          idArr.push(item.id)
          nameArr.push(item.title)
        }
      })
      this.salesIds = idArr
      this.dolderNames = nameArr.join(',')
    },
    getEnum () {
      let groupNames = 'sales.productdeliverystatus'
      commonApi.getEnum({
        groupName: groupNames
      }).then((res) => {
        this.productdeliverystatus = this.getItems(res.data, 'sales.productdeliverystatus')
      })
    },
    getItems (arr, key) {
      let object = arr.find((item) => {
        return item.group === key
      })
      return object.items
    }
  }
}
